package com.four.controller;

import com.four.pojo.After;
import com.four.pojo.Member;
import com.four.pojo.MemberAfter;
import com.four.pojo.Service;
import com.four.service.IAfterService;
import com.four.service.IProductService;
import com.sun.media.sound.SF2GlobalRegion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import sun.management.Agent;

import java.util.Date;
import java.util.List;

/**
 * @author version v1.0
 * @ClassName：
 * @Description：
 **/
@Controller
public class AfterController {
    @Autowired
    @Qualifier(value = "afterService")
    private IAfterService iAfterService;
//售后列表 查询全部
    @RequestMapping("/findAllAfter")
    public String findAllAfter(Model model){
        List<After> list=iAfterService.findAllAfter();
        model.addAttribute("list",list);
        List<Service> service=iAfterService.findAllAservice();
        model.addAttribute("service",service);
        return "afterSales_List.jsp";
    }
    //新增售后里搜索会员
    @RequestMapping("/findAllAmember")
    public String findAllAmember(Model model,String str){
       List<MemberAfter> memberAfters=iAfterService.findAllAmember(str);
       model.addAttribute("memberAfters",memberAfters);
       List<Service> service=iAfterService.findAllAservice();
       model.addAttribute("service",service);
       //获取查出来全部数据中下标为0的数据的id
       if (memberAfters.size()>0){
           model.addAttribute("mid",memberAfters.get(0).getMid());
        }
       return "add_afterSales.jsp";
    }
    //新增售后里服务项目
    @RequestMapping("/findAllAservice")
    public String findAllAservice(Model model){
        List<Service> service=iAfterService.findAllAservice();
        model.addAttribute("service",service);
        return "add_afterSales.jsp";
    }

    @RequestMapping("/addAfter")
    public String addAfter(After after){
        Date date=new Date();
        after.setCreatetime(date);
        System.out.println(after.toString());
        iAfterService.addAfter(after);
        return "redirect:/findAllAfter";
    }
    //售后列表里的 模糊查询
    @RequestMapping("/findByAfter")
    public String findByAfter(Model model,After after){
        System.out.println(after.toString());
        List<Service> service=iAfterService.findAllAservice();
        model.addAttribute("service",service);
        List<After> list=iAfterService.findByAfter(after);
        model.addAttribute("list",list);
        return "afterSales_List.jsp";
    }
}
